import pygame
from pygame.locals import *
import sys

def engine(scenes, curscene=0):
    print "starting at scene:"+str(curscene)

    try:
        scene = scenes[curscene-1]
    except(IndexError):
        scene = scenes[0]
        print "curscene is bigger than possible"

    scene.init()
    print "newscene name:"#+scene
    print curscene
    
    #Starting loop
    while 1:
       scene.loop()
       for event in pygame.event.get():
         if event.type == QUIT:
           sys.exit() #exit the program
         elif event.type == KEYDOWN: #you press a key
           scene.reportKey(event.key) # tell the scene what key it is
       if scene.nextscene != 0:
           print "newscene"#+scene
           curscene = curscene + 1
           scene = scenes[curscene-1]
           scene.init()